package com.dongdongshop.service.impl.pay_log;

import com.dongdongshop.mapper.TbOrderMapper;
import com.dongdongshop.mapper.TbPayLogMapper;
import com.dongdongshop.pojo.order.TbOrder;
import com.dongdongshop.pojo.pay_log.TbPayLog;
import com.dongdongshop.service.pay_log.PayLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class PayLogServiceImpl implements PayLogService {
    @Autowired
    private TbPayLogMapper tbPayLogMapper;
    @Autowired
    private TbOrderMapper tbOrderMapper;
    @Override
    public void insertPayLog(String out_trade_no, String trade_no, String total_amount,String trade_state) {
        TbPayLog tbPayLog = new TbPayLog();
        List<TbOrder> orderList = tbOrderMapper.selectOrderByOrderParent(out_trade_no);
        tbPayLog.setUserId(orderList.get(0).getUserId());
        tbPayLog.setCreateTime(new Date());
        tbPayLog.setOutTradeNo(out_trade_no);
        tbPayLog.setTradeState(trade_state);
        tbPayLog.setTransactionId(trade_no);
        tbPayLog.setTotalFee(Long.getLong(total_amount));
        tbPayLog.setPayTime(new Date());
        tbPayLog.setPayType("1");
        tbPayLogMapper.insertSelective(tbPayLog);
    }
}
